package com.ai.smlcore.util;

import java.io.StringReader;
import java.util.List;

import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;

import net.sf.json.JSONObject;
/**
 * xml转json格式
 * @author Administrator
 *
 */
public class Xml2JsonUtil {

	/**
	 * xml转成json
	 * @param xml
	 * @return
	 * @throws Exception
	 */
	public static JSONObject Xml2Josn(String xml) throws Exception{
		JSONObject rObject= new JSONObject();
		 Document doc = (new SAXBuilder()).build(new StringReader(xml)); 
		 List list = doc.getRootElement().getAttributes();
		 for(int i = 0 ;i<list.size();i++){
		    	Attribute a = (Attribute) list.get(i);
		    	rObject.put(a.getName(), a.getValue());
		    }
		return rObject;
	}
   
}
